/**
 * 2017年6月21日
 */
package cn.edu.bjtu.test.jmx;

import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import org.deeplearning4j.nn.api.Layer;
import org.deeplearning4j.nn.graph.ComputationGraph;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.factory.Nd4j;

import cn.edu.bjtu.model.Deep4jNetworkWrapper;
import cn.edu.bjtu.model.TextCategorizationCNNModel;

/**
 * @author Alex
 *
 */
public class ComputeGraphMBean{
	TextCategorizationCNNModel model = null;
	Deep4jNetworkWrapper wrapper = null;
	/**
	 * 
	 */
	public ComputeGraphMBean() {
		model = TextCategorizationCNNModel.get();
		model.restoreFromFile();
		wrapper = model.getNet();
	}
	
	public static void main(String[] args) throws InterruptedException {
		System.out.println("Process ID:" + getProcessID());
		ComputeGraphMBean x = new ComputeGraphMBean();
		ComputationGraph cg = 	(ComputationGraph)x.wrapper.get();
		x.model.predictDocumentLabelString("曹操是中国历史上一个著名的人物");
		Layer[] layers = cg.getLayers();
		int len = layers.length;
		Arrays.asList(layers).forEach(System.out::println);
		INDArray arr = Nd4j.ones(300); 
//		cg.setInputs(arr);
		Layer l = cg.getLayer(len-1);
		l.setInput(arr);
		System.out.println(l.activate());
		System.out.println();
		
	}
    public static final int getProcessID() {  
        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        return Integer.valueOf(runtimeMXBean.getName().split("@")[0])  
                .intValue();  
    } 

}
